import java.sql.ResultSet;
import java.util.Collection;

public class DoctorsOrders {
	private int treatmentRecordId;
	private String value;

	public DoctorsOrders() {
		treatmentRecordId = -1;
		value = null;
	}

	public TreatmentRecord getTreatmentRecord() {
		if (this.treatmentRecordId < 1)
		{
			return null;
		}
		else
		{
			return TreatmentRecord.readTreatmentRecord(treatmentRecordId);
		}
	}

	public void setTreatmentRecord(int recordId) {
		this.treatmentRecordId = recordId;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	// CRUD functionality beyond here

	// Create
	public static boolean createDoctorsOrders(int TreatmentRecordId,
			String value) {
		String sql = "INSERT INTO DoctorsOrders VALUES (" + TreatmentRecordId
				+ ", '" + value + "')";
		int rows = Database.query(sql);
		if (rows == 1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	// Read
	public static DoctorsOrders readDoctorsOrders(int TreatmentRecordId) {
		String sql = "SELECT * FROM DoctorsOrders WHERE treatment_record="
				+ TreatmentRecordId;
		ResultSet rs = Database.selectQuery(sql);
		DoctorsOrders doctorsOrders = new DoctorsOrders();
		try {
			rs.next();
			doctorsOrders.setTreatmentRecord(TreatmentRecordId);
			doctorsOrders.setValue(rs.getString("value"));
		} catch (Exception e) {
		}
		return doctorsOrders;
	}

	// Update
	public static boolean updateDoctorsOrders(int TreatmentRecordId,
			String value) {
		String sql = "UPDATE DoctorsOrders SET value='" + value
				+ "' WHERE treatment_record=" + TreatmentRecordId;
		int rows = Database.query(sql);
		if (rows == 1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

	// Delete
	public static boolean deleteDoctorsOrders(int TreatmentRecordId) {
		String sql = "DELETE FROM DoctorsOrders WHERE treatment_record="
				+ TreatmentRecordId;
		int rows = Database.query(sql);
		if (rows == 1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
